package cn.edu.sgu.www.mhxysy.controller.except;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.except.ImageRenameService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "图片重命名管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(value = "/image", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ImageRenameController {

    private final ImageRenameService imageRenameService;

    @Autowired
    public ImageRenameController(ImageRenameService imageRenameService) {
        this.imageRenameService = imageRenameService;
    }

    @ApiOperation("图片重命名")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tableName", value = "表名", required = true),
            @ApiImplicitParam(name = "imageField", value = "图片字段名", defaultValue = "image", required = false)
    })
    @RequestMapping(value = "/rename", method = RequestMethod.POST)
    public JsonResult<Void> rename(
            @NotBlank(message = "表名" + CustomMessages.NOT_NULL) String tableName,
            @RequestParam(required = false, defaultValue = "image") String imageField) {
        imageRenameService.rename(tableName, imageField);

        return JsonResult.success("操作成功");
    }

}